<?php if(! defined('BASEPATH')) exit('No direct script access allowed');
class User_model extends CI_Model{

    public function __construct(){
        parent::__construct();
    }

    function login($email,$password){
        $this->db->where("email", $email);
        $this->db->where("password", md5($password));

        $query=$this->db->get("usuarios");
        if($query->num_rows()>0){
            foreach($query->result() as $rows){
                $newdata = array(
                    'user_id'   =>$rows->id_usuario,
                    'user_name' =>$rows->username,
                    'user_email'=>$rows->email,
                    'logged_in' =>TRUE
                );
            }
            $this->session->set_userdata($newdata);
            return true;
        }
        return false;
    }

    public function add_user(){
        $data=array(
            'username'  => $this->input->post('user_name'),
            'email'     => $this->input->post('email_address'),
            'password'  => md5($this->input->post('password'))
        );
        $this->db->insert('usuarios', $data);
    }
}


?>